package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsCopyRightMapper;
import net.anzhuo.entity.GsCopyRight;
import net.anzhuo.service.GsCopyRightService;

@Service
public class GsCopyRightServiceImpl implements GsCopyRightService {

	@Autowired
	private GsCopyRightMapper gsCopyRightMapper;

	@Override
	public PaginationVO<GsCopyRight> getListWithPage(GsCopyRight gsCopyRight) {
		PaginationVO<GsCopyRight> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsCopyRightMapper.getListWithPage(gsCopyRight));
		paginationVO.setTotalCount(gsCopyRightMapper.getCount(gsCopyRight));
		paginationVO.setTotalPage((gsCopyRightMapper.getCount(gsCopyRight) + gsCopyRight.getPageSize() -1)  / gsCopyRight.getPageSize());
		paginationVO.setPageNo(gsCopyRight.getPageNo());
		return paginationVO;
	}

	@Override
	public GsCopyRight getById(Long id) {
		return gsCopyRightMapper.getById(id);
	}

	@Override
	public List<GsCopyRight> getList() {
		return gsCopyRightMapper.getList();
	}

	@Override
	public List<GsCopyRight> getList(GsCopyRight gsZhuzuoquan) {
		return gsCopyRightMapper.getListByQuery(gsZhuzuoquan);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsCopyRight gsZhuzuoquan) {
		gsCopyRightMapper.update(gsZhuzuoquan);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsCopyRight gsZhuzuoquan) {
		gsCopyRightMapper.save(gsZhuzuoquan);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsCopyRight gsZhuzuoquan = gsCopyRightMapper.getById(id);
		if (gsZhuzuoquan == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsCopyRightMapper.update(gsZhuzuoquan);
	}

	@Override
	public List<GsCopyRight> getByMd5(String md5) {
		return gsCopyRightMapper.getByMd5(md5);
	}
}
